// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CLOUDAPPENGINE_CAEDEFINE_H
#define CLOUDAPPENGINE_CAEDEFINE_H

#include <string>
#define ENUM_CHIP_TYPE_CASE(x) \
    case x:                    \
        return (#x);
#define STATUS2STR(val) (char *)(#val)

#define ENABLE_SIGNATURE (0)        // 请求是否使用签名
#define ENABLE_TCP_SERVER (0)       // 是否开启TCP server
#define ENABLE_WEBSOCKET_SERVER (0) // 是否开启web socket server

#define ENABLE_WSS_SERVER (1)     // WSS支持
#define PARSE_HTTPS_RESPONSE (0)  // 解析Https的response

#define DEBUG_CODE (0)      // 是否开启调试代码段
#define DEBUG_STAT_PKT (0)  // 统计每秒收包代码开关
#define PRINT_THREAD_ID (0) // 是否获取当前的线程ID

#define ENABLE_INJECT_LOCAL_CAMERA_STREAM (0)
#define ENABLE_INJECT_LOCAL_MICROPHONE_STREAM (0)

const int CAE_MSG_INVALID = 0; // 无效
const int CAE_MSG_VERIFY = 1;  // 认证
const int CAE_MSG_AUDIO = 2;   // 音频数据
const int CAE_MSG_VIDEO = 3;   // 视频编码后数据
const int CAE_MSG_CHANNEL = 4;  // 自定义数据通道数据，真机和云机应用的双向数据通道
const int CAE_MSG_TOUCH = 6;          // 触摸数据
const int CAE_MSG_CONTROL = 7;        // 控制
const int CAE_MSG_APK_HEART_BEAT = 8; // APK心跳数据
const int CAE_MSG_ORIENTATION = 9;    // 旋转信息
const int CAE_MSG_SCREENSHOT = 10;    // 截图数据

const int CAE_MSG_IME = 14;          // 输入法
const int CAE_MSG_KEY_EVENT = 15;    // 遥控器
const int CAE_MSG_MOTION_EVENT = 16; // 手柄

const int CAE_MSG_VIRTUAL_DEVICE = 20;          // 虚拟设备
const int CAE_MSG_VIRTUAL_CAMERA = 21;          // 摄像头
const int CAE_MSG_VIRTUAL_MICROPHONE = 22;      // 麦克风
const int CAE_MSG_VIRTUAL_SENSOR = 23;          // 传感器
const int CAE_MSG_VIRTUAL_LOCATION = 24;        // 位置信息
const int CAE_MSG_VIRTUAL_VIBRATOR = 25;        // 震动信息

const uint16_t CAE_STREAM_DELIMITER_MAGICWORD = 0x5A5A;

#define GET_CAE_CHECKSUM(msg_type) \
    (((msg_type) + ((CAE_STREAM_DELIMITER_MAGICWORD >> 8) & 0xFF) + (CAE_STREAM_DELIMITER_MAGICWORD & 0xFF)) & 0xFF)
#define CAE_MSG_DELIMITER(type) ((CAE_STREAM_DELIMITER_MAGICWORD << 16) + (GET_CAE_CHECKSUM(type) << 8) + type)

const std::string AUDIO_PIPE = "audio";
const std::string VIDEO_PIPE = "video";
const std::string CONTROL_PIPE = "control";
const std::string CHANNEL_PIPE = "channel";
const std::string IME_PIPE = "ime";
const std::string SCREENSHOT_PIPE = "screenshot";
const std::string VIRTUAL_DEVICE_PIPE = "virtual_device";

const int DATA_SHAREMEM_SIZE = (512 * 1024);

const int SOCKET_RECV_FAIL_RETRY = -1;   // 接收函数返回失败，可再调接收函数重试
const int SOCKET_RECV_FAIL_DISCONN = -2; // 接收函数返回失败，SOCKET断链，不可用
const int SOCKET_SEND_FAIL_RETRY = -3;   // 发送函数返回失败，可再调发送函数重试
const int SOCKET_SEND_FAIL_DISCONN = -4; // 发送函数返回失败，SOCKET断链，不可用

const int SOCKET_OPTION_BITSET_NODELAY = 0x1;
const int SOCKET_OPTION_BITSET_QUICKACK = 0x2;

const int DEV_OPT_GNSS_LOCATION_DATA_REQ = 0x2; // GNSS Location定位数据回调

enum CaeAgentStatus {
    CAE_AGENT_INIT,           // 初始化
    CAE_AGENT_RUNING,         // 运行中
    CAE_AGENT_PAUSE,          // 暂停
    CAE_AGENT_WAIT_RECONNECT, // 等待重连
    CAE_AGENT_EXIT,           // 退出
};

enum ClientType {
    APP_TCP,
    APP_TLS,
    H5_WS,
    H5_WSS,
    CLIENT_TYPE,
};

enum ClientPlatformType {
    PLATFORM_ANDROID = 1,
    PLATFORM_WINDOWS,
    PLATFORM_H5_PC,
    PLATFORM_H5_MOBILE,
    PLATFORM_IOS,
    CLIENT_PLATFORM_TYPE_MAX
};

enum ServerType {
    TCP,
    TLS,
    WS,
    WSS,
    SERVER_TYPE,
};

const int CAE_THREAD_STATUS_NEW = 0;
const int CAE_THREAD_STATUS_RUNNING = 1;
const int CAE_THREAD_STATUS_STOP = 2;
const int CAE_THREAD_STATUS_EXIT = -1;

const int ANDROID_7_1_1_SDK_VERSION = 25;
const int ANDROID_9_SDK_VERSION = 28;
const int ANDROID_11_SDK_VERSION = 30;

const std::string CLIENT_MODE_DIRECT = "direct";
const std::string CLIENT_MODE_MANAGEMENT = "management";

const std::string CLIENT_KEY_VERSION = "24.3.0";
// 用于区分sensor1.0和sensor2.0，在SDK版本为24.6.0前，sensor注入均采用1.0模式
const std::string SENSOR_CLIENT_KEY_VERSION = "24.6.0";

#endif // CLOUDAPPENGINE_CAEDEFINE_H
